package com.centaline.androidsalesblog.fragments.listmap;

import android.content.Intent;
import android.os.Bundle;

import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.Marker;
import com.centaline.androidsalesblog.activities.sale.EsfEstateDetailActivity;
import com.centaline.androidsalesblog.base.BaseListMapFragment;
import com.centaline.androidsalesblog.constants.ExtraConstant;
import com.centaline.androidsalesblog.iml.BaiduMarkerClick;
import com.centaline.androidsalesblog.model.databaseobject.EsfEstateDo;
import com.centaline.androidsalesblog.overlay.local.EsfEstateListMapOverlay;

/**
 * 小区列表地图
 * Created by guilin on 16/4/13.
 */
public class EsfEstateListMapFragment extends BaseListMapFragment<EsfEstateDo> {

    private EsfEstateListMapOverlay esfEstateListMapOverlay;

    @Override
    protected void initView() {
        super.initView();
        esfEstateListMapOverlay = new EsfEstateListMapOverlay(getActivity(), baiduMap, mapArrayList, new BaiduMarkerClick() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                if (marker != null) {
                    Bundle bundle = marker.getExtraInfo();
                    if (bundle != null) {
                        if (bundle.getParcelable(ExtraConstant.MAP_EXTRA_INFO) instanceof EsfEstateDo) {
                            EsfEstateDo esfEstateDo = bundle.getParcelable(ExtraConstant.MAP_EXTRA_INFO);
                            if (esfEstateDo != null) {
                                startActivity(new Intent(getContext(), EsfEstateDetailActivity.class)
                                        .putExtra(ExtraConstant.CestCode, esfEstateDo.getCestCode()));
                                return true;
                            }
                        }
                    }
                }
                return false;
            }
        });
        baiduMap.setOnMarkerClickListener(esfEstateListMapOverlay);
    }

    @Override
    protected void resetMap() {
        mapStatusChangeTag = 1;
        esfEstateListMapOverlay.addFirstToMap();
    }

    @Override
    protected void refreshMap() {

    }

    @Override
    public void onMapStatusChangeFinish(MapStatus mapStatus) {
        super.onMapStatusChangeFinish(mapStatus);
        if (mapStatusChangeTag == 1) {
            esfEstateListMapOverlay.addToMap(false);
        } else {
            esfEstateListMapOverlay.mapStatusChange();
        }
        mapStatusChangeTag = 0;
    }
}
